home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / cweb31.zip / CWEBMAC.TEX (.txt) < prev    next >
LaTeX Document  |  1993-06-12  |  15KB  |  316 lines

  1. % standard macros for CWEB listings (in addition to plain.tex)
  2. % Version 3.0 --- June 1993
  3. \ifx\documentstyle\undefined\else\endinput\fi % LaTeX will use other macros
  4. \xdef\fmtversion{\fmtversion+CWEB3.0}
  5. \let\:=\. % preserve a way to get the dot accent
  6.  % (all other accents will still work as usual)
  7. \parskip 0pt % no stretch between paragraphs
  8. \parindent 1em % for paragraphs and for the first line of C text
  9. \font\ninerm=cmr9
  10. \let\mc=\ninerm % medium caps
  11. \def\CEE/{{\mc C\spacefactor1000}}
  12. \def\UNIX/{{\mc U\kern-.05emNIX\spacefactor1000}}
  13. \def\TEX/{\TeX}
  14. \def\CPLUSPLUS/{{\mc C\PP\spacefactor1000}}
  15. \def\Cee{\CEE/} % for backward compatibility
  16. \def\9#1{}
  17. \font\eightrm=cmr8
  18. \let\sc=\eightrm % small caps (NOT a caps-and-small-caps font)
  19. \let\mainfont=\tenrm
  20. \let\cmntfont\tenrm
  21. %\font\tenss=cmss10 \let\cmntfont\tenss % alternative comment font
  22. \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
  23. \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
  24. \font\tentex=cmtex10 % TeX extended character set (used in strings)
  25. \fontdimen7\tentex=0pt % no double space after sentences
  26. \def\\#1{\leavevmode\hbox{\it#1\/\kern.05em}} % italic type for identifiers
  27. \def\|#1{\leavevmode\hbox{$#1$}} % one-letter identifiers look better this way
  28. \def\{\leavevmode\hbox{\bf
  29.   \def\_{\kern.04em\vbox{\hrule width.3em height .6pt}\kern.08em}%
  30.   #1\/\kern.05em}} % boldface type for reserved words
  31. \def\.#1{\leavevmode\hbox{\tentex % typewriter type for strings
  32.   \let\\=\BS % backslash in a string
  33.   \let\{=\LB % left brace in a string
  34.   \let\}=\RB % right brace in a string
  35.   \let\~=\TL % tilde in a string
  36.   \let\ =\SP % space in a string
  37.   \let\_=\UL % underline in a string
  38.   \let\&=\AM % ampersand in a string
  39.   \let\^=\CF % circumflex in a string
  40.   #1\kern.05em}}
  41. \def\){\discretionary{\hbox{\tentex\BS}}{}{}}
  42. \def\AT{@} % at sign for control text (not needed in versions >= 2.9)
  43. \def\ATL{\par\noindent\bgroup\catcode`\_=12 \postATL} % print @l in limbo
  44. \def\postATL#1 #2 {\bf letter \\{\uppercase{\char"#1}}
  45.    tangles as \tentex "#2"\egroup\par}
  46. \def\noATL#1 #2 {}
  47. \def\noatl{\let\ATL=\noATL} % suppress output from @l
  48. \def\ATH{\X\kern-.5em:Preprocessor definitions\X}
  49. \let\PB=\relax % hook for program brackets |...| in TeX part or section name
  50. \chardef\AM=`\& % ampersand character in a string
  51. \chardef\BS=`\\ % backslash in a string
  52. \chardef\LB=`\{ % left brace in a string
  53. \chardef\RB=`\} % right brace in a string
  54. \def\SP{{\tt\char`\ }} % (visible) space in a string
  55. \chardef\TL=`\~ % tilde in a string
  56. \chardef\UL=`\_ % underline character in a string
  57. \chardef\CF=`\^ % circumflex character in a string
  58. \newbox\PPbox % symbol for ++
  59. \setbox\PPbox=\hbox{\kern.5pt\raise1pt\hbox{\sevenrm+\kern-1pt+}\kern.5pt}
  60. \def\PP{\copy\PPbox}
  61. \newbox\MMbox \setbox\MMbox=\hbox{\kern.5pt\raise1pt\hbox{\sevensy\char0
  62.  \kern-1pt\char0}\kern.5pt}
  63. \def\MM{\copy\MMbox}
  64. \newbox\MGbox % symbol for ->
  65. \setbox\MGbox=\hbox{\kern-2pt\lower3pt\hbox{\teni\char'176}\kern1pt}
  66. \def\MG{\copy\MGbox}
  67. \def\MRL#1{\mathrel{\let\K==#1}}
  68. %\def\MRL#1{\KK#1}\def\KK#1#2{\buildrel\;#1\over{#2}}
  69. \let\GG=\gg
  70. \let\LL=\ll
  71. \let\NULL=\Lambda
  72. \mathchardef\AND="2026 % bitwise and; also \& (unary operator)
  73. \let\OR=\mid % bitwise or
  74. \let\XOR=\oplus % bitwise exclusive or
  75. \def\CM{{\sim}} % bitwise complement
  76. \newbox\MODbox \setbox\MODbox=\hbox{\eightrm\%}
  77. \def\MOD{\mathbin{\copy\MODbox}}
  78. \def\DC{\kern.1em{::}\kern.1em} % symbol for ::
  79. \def\PA{\mathbin{.*}} % symbol for .*
  80. \def\MGA{\mathbin{\MG*}} % symbol for ->*
  81. \def\this{\&{this}}
  82. \newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
  83. \newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
  84. \newcount\ind % current indentation in ems
  85. \def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
  86. \def\2{\global\advance\ind by-1} % indent one less notch
  87. \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
  88. \def\4{\copy\bak} % backspace one notch
  89. \def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
  90. \def\6{\ifmmode\else\par % forced break
  91.   \hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
  92. \def\7{\Y\6} % forced break and a little extra space
  93. \def\8{\hskip-\ind em\hskip 2em} % no indentation
  94. \newcount\gdepth % depth of current major group, plus one
  95. \newcount\secpagedepth
  96. \secpagedepth=3 % page breaks will occur for depths -1, 0, and 1
  97. \newtoks\gtitle % title of current major group
  98. \newskip\intersecskip \intersecskip=12pt minus 3pt % space between sections
  99. \let\yskip=\smallskip
  100. \def\?{\mathrel?}
  101. \def\note#1#2.{\Y\noindent{\hangindent2em\baselineskip10pt\eightrm#1~#2.\par}}
  102. \def\lapstar{\rlap{*}}
  103. \def\stsec{\rightskip=0pt % get out of C mode (cf. \B)
  104.   \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50
  105.   \noindent{\let\*=\lapstar\bf\secstar.\quad}}
  106. \let\startsection=\stsec
  107. \def\defin#1{\global\advance\ind by 2 \1\&{#1 } } % begin `define' or `format'
  108. \def\A{\note{See also section}} % xref for doubly defined section name
  109. \def\As{\note{See also sections}} % xref for multiply defined section name
  110. \def\B{\rightskip=0pt plus 100pt minus 10pt % go into C mode
  111.   \sfcode`;=3000
  112.   \pretolerance 10000
  113.   \hyphenpenalty 9999 % so strings can be broken (discretionary \ is inserted)
  114.   \exhyphenpenalty 10000
  115.   \global\ind=2 \1\ \unskip}
  116. \def\C#1{\5\5\quad$/\ast\,${\cmntfont #1}$\,\ast/$}
  117. \let\SHC\C % "// short comments" treated like "/* ordinary comments */"
  118. %\def\C#1{\5\5\quad$\triangleright\,${\cmntfont#1}$\,\triangleleft$}
  119. %\def\SHC#1{\5\5\quad$\diamond\,${\cmntfont#1}}
  120. \def\D{\defin{\#define}} % macro definition
  121. \let\E=\equiv % equivalence sign
  122. \def\ET{ and~} % conjunction between two section numbers
  123. \def\ETs{, and~} % conjunction between the last two of several section numbers
  124. \def\F{\defin{format}} % format definition
  125. \let\G=\ge % greater than or equal sign
  126. % \H is long Hungarian umlaut accent
  127. \let\I=\ne % unequal sign
  128. \def\J{\.{@\&}} % TANGLE's join operation
  129. \let\K== % assignment operator
  130. %\let\K=\leftarrow % "honest" alternative to standard assignment operator
  131. % \L is Polish letter suppressed-L
  132. \outer\def\M#1{\MN{#1}\ifon\vfil\penalty-100\vfilneg % beginning of section
  133.   \vskip\intersecskip\startsection\ignorespaces}
  134. \outer\def\N#1#2#3.{\gdepth=#1\gtitle={#3}\MN{#2}% beginning of starred section
  135.   \ifon\ifnum#1<\secpagedepth \vfil\eject % force page break if depth is small
  136.     \else\vfil\penalty-100\vfilneg\vskip\intersecskip\fi\fi
  137.   \message{*\secno} % progress report
  138.   \edef\next{\write\cont{\ZZ{#3}{#1}{\secno}% write to contents file
  139.                    {\noexpand\the\pageno}}}\next % \ZZ{title}{depth}{sec}{page}
  140.   \ifon\startsection{\bf#3.\quad}\ignorespaces}
  141. \def\MN#1{\par % common code for \M, \N
  142.   {\xdef\secstar{#1}\let\*=\empty\xdef\secno{#1}}% remove \* from section name
  143.   \ifx\secno\secstar \onmaybe \else\ontrue \fi
  144.   \mark{{{\tensy x}\secno}{\the\gdepth}{\the\gtitle}}}
  145. % each \mark is {section reference or null}{depth plus 1}{group title}
  146. % \O is Scandinavian letter O-with-slash
  147. % \P is paragraph sign
  148. \def\Q{\note{This code is cited in section}} % xref for mention of a section
  149. \def\Qs{\note{This code is cited in sections}} % xref for mentions of a section
  150. \let\R=\lnot % logical not
  151. % \S is section sign
  152. \def\T#1{\leavevmode % octal, hex or decimal constant
  153.   \hbox{$\def\?{\kern.2em}%
  154.     \def\$##1{\egroup_{\,\rm##1}\bgroup}% suffix to constant
  155.     \def\_{\cdot 10^{\aftergroup}}% power of ten (via dirty trick)
  156.     \let\~=\oct \let\^=\hex {#1}$}}
  157. \def\U{\note{This code is used in section}} % xref for use of a section
  158. \def\Us{\note{This code is used in sections}} % xref for uses of a section
  159. \let\V=\lor % logical or
  160. \let\W=\land % logical and
  161. \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % section name
  162.   \XX$\langle\,${#2\eightrm\kern.5em#1}$\,\rangle$\XX}
  163. \def\Y{\par\yskip}
  164. \let\Z=\le
  165. \let\ZZ=\let % now you can \write the control sequence \ZZ
  166. \let\*=*
  167. %\def\oct{\hbox{\rm\char'23\kern-.2em\it\aftergroup\?\aftergroup}} % WEB style
  168. %\def\hex{\hbox{\rm\char"7D\tt\aftergroup}} % WEB style
  169. \def\oct{\hbox{$^\circ$\kern-.1em\it\aftergroup\?\aftergroup}}% CWEB style
  170. \def\hex{\hbox{$^{\scriptscriptstyle\#}$\tt\aftergroup}} % CWEB style
  171. \def\vb#1{\leavevmode\hbox{\kern2pt\vrule\vtop{\vbox{\hrule
  172.         \hbox{\strut\kern2pt\.{#1}\kern2pt}}
  173.       \hrule}\vrule\kern2pt}} % verbatim string
  174. \def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue
  175. \newif\ifon \newif\iftitle \newif\ifpagesaved
  176. \def\lheader{\mainfont\the\pageno\eightrm\qquad\grouptitle\hfill\title\qquad
  177.   \mainfont\topsecno} % top line on left-hand pages
  178. \def\rheader{\mainfont\topsecno\eightrm\qquad\title\hfill\grouptitle
  179.   \qquad\mainfont\the\pageno} % top line on right-hand pages
  180. \def\grouptitle{\let\i=I\let\j=J\uppercase\expandafter{\expandafter
  181.                         \takethree\topmark}}
  182. \def\topsecno{\expandafter\takeone\topmark}
  183. \def\takeone#1#2#3{#1}
  184. \def\taketwo#1#2#3{#2}
  185. \def\takethree#1#2#3{#3}
  186. \def\nullsec{\eightrm\kern-2em} % the \kern-2em cancels \qquad in headers
  187. \let\page=\pagebody \raggedbottom
  188. % \def\page{\box255 }\normalbottom % faster, but loses plain TeX footnotes
  189. \def\normaloutput#1#2#3{\shipout\vbox{
  190.   \ifodd\pageno\hoffset=\pageshift\fi
  191.   \vbox to\fullpageheight{
  192.   \iftitle\global\titlefalse
  193.   \else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
  194.   \vfill#1}} % parameter #1 is the page itself
  195.   \global\advance\pageno by1}
  196. \gtitle={\.{CWEB} output} % this running head is reset by starred sections
  197. \mark{\noexpand\nullsec0{\the\gtitle}}
  198. \def\title{\expandafter\uppercase\expandafter{\jobname}}
  199. \def\topofcontents{\centerline{\titlefont\title}\vskip.7in
  200.   \vfill} % this material will start the table of contents page
  201. \def\botofcontents{\vfill
  202.   \centerline{\covernote}} % this material will end the table of contents page
  203. \def\covernote{}
  204. \def\contentspagenumber{0} % default page number for table of contents
  205. \newdimen\pagewidth \pagewidth=6.5in % the width of each page
  206. \newdimen\pageheight \pageheight=8.7in % the height of each page
  207. \newdimen\fullpageheight \fullpageheight=9in % page height including headlines
  208. \newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones
  209. \def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
  210.   \fullpageheight=9truein\setpage}
  211. \def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
  212. \def\contentsfile{\jobname.toc} % file that gets table of contents info
  213. \def\readcontents{\input \contentsfile}
  214. \def\readindex{\input \jobname.idx}
  215. \def\readsections{\input \jobname.scn}
  216. \newwrite\cont
  217. \output{\setbox0=\page % the first page is garbage
  218.   \openout\cont=\contentsfile
  219.        \write\cont{\catcode `\noexpand\@=11\relax}   % \makeatletter
  220.   \global\output{\normaloutput\page\lheader\rheader}}
  221. \setpage
  222. \vbox to \vsize{} % the first \topmark won't be null
  223. \def\ch{\note{The following sections were changed by the change file:}
  224.   \let\*=\relax}
  225. \newbox\sbox % saved box preceding the index
  226. \newbox\lbox % lefthand column in the index
  227. \def\inx{\par\vskip6pt plus 1fil % we are beginning the index
  228.   \def\page{\box255 } \normalbottom
  229.   \write\cont{} % ensure that the contents file isn't empty
  230.        \write\cont{\catcode `\noexpand\@=12\relax}   % \makeatother
  231.   \closeout\cont % the contents information has been fully gathered
  232.   \output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
  233.     \global\setbox\sbox=\page \global\pagesavedtrue}
  234.   \pagesavedfalse \eject % eject the page-so-far and predecessors
  235.   \setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
  236.   \vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
  237.   \hsize=.5\pagewidth \advance\hsize by -10pt
  238.     % column width for the index (20pt between cols)
  239.   \parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
  240.   \def\lr{L} % this tells whether the left or right column is next
  241.   \output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
  242.     \else\normaloutput{\vbox to\pageheight{\box\sbox\vss
  243.         \hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
  244.     \global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
  245.   \message{Index:}
  246.   \parskip 0pt plus .5pt
  247.   \outer\def\I##1, {\par\hangindent2em\noindent##1:\kern1em} % index entry
  248.   \def\[##1]{$\underline{##1}$} % underlined index item
  249.   \rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
  250.   \hyphenpenalty 10000 \parindent0pt
  251.   \readindex}
  252. \def\fin{\par\vfill\eject % this is done when we are ending the index
  253.   \ifpagesaved\null\vfill\eject\fi % output a null index column
  254.   \if L\lr\else\null\vfill\eject\fi % finish the current page
  255.   \parfillskip 0pt plus 1fil
  256.   \def\grouptitle{NAMES OF THE SECTIONS}
  257.   \let\topsecno=\nullsec
  258.   \message{Section names:}
  259.   \output={\normaloutput\page\lheader\rheader}
  260.   \setpage
  261.   \def\note##1##2.{\quad{\eightrm##1~##2.}}
  262.   \def\Q{\note{Cited in section}} % crossref for mention of a section
  263.   \def\Qs{\note{Cited in sections}} % crossref for mentions of a section
  264.   \def\U{\note{Used in section}} % crossref for use of a section
  265.   \def\Us{\note{Used in sections}} % crossref for uses of a section
  266.   \def\I{\par\hangindent 2em}\let\*=*
  267.   \readsections}
  268. \def\con{\par\vfill\eject % finish the section names
  269. % \ifodd\pageno\else\titletrue\null\vfill\eject\fi % for duplex printers
  270.   \rightskip 0pt \hyphenpenalty 50 \tolerance 200
  271.   \setpage \output={\normaloutput\page\lheader\rheader}
  272.   \titletrue % prepare to output the table of contents
  273.   \pageno=\contentspagenumber
  274.   \def\grouptitle{TABLE OF CONTENTS}
  275.   \message{Table of contents:}
  276.   \topofcontents
  277.   \line{\hfil Section\hbox to3em{\hss Page}}
  278.   \let\ZZ=\contentsline
  279.   \readcontents\relax % read the contents info
  280.   \botofcontents \end} % print the contents page(s) and terminate
  281. \def\contentsline#1#2#3#4{\ifnum#2=0 \smallbreak\fi
  282.     \line{\consetup{#2}#1
  283.       \rm\leaders\hbox to .5em{.\hfil}\hfil\ #3\hbox to3em{\hss#4}}}
  284. \def\consetup#1{\ifcase#1 \bf % depth -1 (@**)
  285.   \or % depth 0 (@*)
  286.   \or \hskip2em % depth 1 (@*1)
  287.   \or \hskip4em % depth 2 (@*2)
  288.   \or \hskip6em % depth 3 (@*3)
  289.   \or \hskip8em % depth 4 (@*4)
  290.   \or \hskip10em % depth 5 (@*5)
  291.   \else \hskip12em \fi} % depth 6 or more
  292. \def\noinx{\let\inx=\end} % no indexes or table of contents
  293. \def\nosecs{\let\FIN=\fin \def\fin{\let\parfillskip=\end \FIN}}
  294.     % no index of section names or table of contents
  295. \def\nocon{\let\con=\end} % no table of contents
  296. \def\today{\ifcase\month\or
  297.   January\or February\or March\or April\or May\or June\or
  298.   July\or August\or September\or October\or November\or December\fi
  299.   \space\number\day, \number\year}
  300. \newcount\twodigits
  301. \def\hours{\twodigits=\time \divide\twodigits by 60 \printtwodigits
  302.   \multiply\twodigits by-60 \advance\twodigits by\time :\printtwodigits}
  303. \def\gobbleone1{}
  304. \def\printtwodigits{\advance\twodigits100
  305.   \expandafter\gobbleone\number\twodigits
  306.   \advance\twodigits-100 }
  307. \def\TeX{{\ifmmode\it\fi
  308.    \leavevmode\hbox{T\kern-.1667em\lower.424ex\hbox{E}\hskip-.125em X}}}
  309. \def\,{\relax\ifmmode\mskip\thinmuskip\else\thinspace\fi}
  310. \def\datethis{\def\startsection{\leftline{\sc\today\ at \hours}\bigskip
  311.   \let\startsection=\stsec\stsec}}
  312.   % say `\datethis' in limbo, to get your listing timestamped before section 1
  313. \def\datecontentspage{%
  314.   \def\topofcontents{\leftline{\sc\today\ at \hours}\bigskip
  315.    \centerline{\titlefont\title}\vfill}} % timestamps the contents page
  316.